// nettest.cc 
//	Test out message delivery between two "Nachos" machines,
//	using the Post Office to coordinate delivery.
//
//	Two caveats:
//	  1. Two copies of Nachos must be running, with machine ID's 0 and 1:
//		./nachos -m 0 -o 1 &
//		./nachos -m 1 -o 0 &
//
//	  2. You need an implementation of condition variables,
//	     which is *not* provided as part of the baseline threads 
//	     implementation.  The Post Office won't work without
//	     a correct implementation of condition variables.
//
// Copyright (c) 1992-1993 The Regents of the University of California.
// All rights reserved.  See copyright.h for copyright notice and limitation 
// of liability and disclaimer of warranty provisions.

#include "copyright.h"

#include "system.h"
#include "network.h"
#include "post.h"
#include "interrupt.h"
#include "client.h"

// Test out message delivery, by doing the following:
//	1. send a message to the machine with ID "farAddr", at mail box #0
//	2. wait for the other machine's message to arrive (in our mailbox #0)
//	3. send an acknowledgment for the other machine's message
//	4. wait for an acknowledgement from the other machine to our 
//	    original message

void
MailTest(int farAddr)
{
    PacketHeader outPktHdr, inPktHdr;
    MailHeader outMailHdr, inMailHdr;
    char *data = "Hello there!";
    char *ack = "Got it!";
    char buffer[MaxMailSize];

    // construct packet, mail header for original message
    // To: destination machine, mailbox 0
    // From: our machine, reply to: mailbox 1
    outPktHdr.to = farAddr;		
    outMailHdr.to = 0;
    outMailHdr.from = 1;
    outMailHdr.length = strlen(data) + 1;

    // Send the first message
    bool success = postOffice->Send(outPktHdr, outMailHdr, data); 

    if ( !success ) {
		printf("The postOffice Send failed. You must not have the other Nachos running. Terminating Nachos.\n");
		interrupt->Halt();
    }

    // Wait for the first message from the other machine
	printf("nettest print\n");
    postOffice->Receive(0, &inPktHdr, &inMailHdr, buffer);
    printf("Got \"%s\" from %d, box %d\n",buffer,inPktHdr.from,inMailHdr.from);
    fflush(stdout);

    // Send acknowledgement to the other machine (using "reply to" mailbox
    // in the message that just arrived
    outPktHdr.to = inPktHdr.from;
    outMailHdr.to = inMailHdr.from;
    outMailHdr.length = strlen(ack) + 1;
	printf("NEXT nettest print\n");
    success = postOffice->Send(outPktHdr, outMailHdr, ack); 

    if ( !success ) {
      printf("The postOffice Send failed. You must not have the other Nachos running. Terminating Nachos.\n");
      interrupt->Halt();
    }

    // Wait for the ack from the other machine to the first message we sent.
	printf("FINAL nettest print\n");
    postOffice->Receive(1, &inPktHdr, &inMailHdr, buffer);
    printf("Got \"%s\" from %d, box %d\n",buffer,inPktHdr.from,inMailHdr.from);
    fflush(stdout);

    // Then we're done!
	printf("nettest finished\n");
    interrupt->Halt();
}

void ServerTest(int farAddr) {
	PacketHeader outPktHdr, inPktHdr;
	MailHeader outMailHdr, inMailHdr;
	char *data = "Hello there!";
	char *ack = "Got it!";
	char buffer[MaxMailSize];
	int success;

	// construct packet, mail header for original message
	// To: destination machine, mailbox 0
	// From: our machine, reply to: mailbox 1
	outPktHdr.to = farAddr;		
	outMailHdr.to = 0;
	outMailHdr.from = myMachID;
	outMailHdr.length = strlen(data) + 1;
	
	int testLockNum;

	// Send the create lock message
	/*printf("Sending create lock message (Normative)\n");
	testLockNum = ClientCreateLock("test1");
	if(testLockNum == -1) {
		printf("Create Lock (Normative) failed!\n\n");
	}
	else {
		printf("Create Lock (Normative) succeeded! %i\n\n", testLockNum);
	}
	printf("Sending create lock message (Normative)\n");
	testLockNum = ClientCreateLock("test2");
	if(testLockNum == -1) {
		printf("Create Lock (Normative) failed!\n\n");
	}
	else {
		printf("Create Lock (Normative) succeeded! %i\n\n", testLockNum);
	}
	printf("Sending create lock message (Normative)\n");
	testLockNum = ClientCreateLock("test3");
	if(testLockNum == -1) {
		printf("Create Lock (Normative) failed!\n\n");
	}
	else {
		printf("Create Lock (Normative) succeeded! %i\n\n", testLockNum);
	}*/

	char* testLock = "testLock";
	
	// Send the create lock message
	printf("Sending create lock message (Normative)\n");
	testLockNum = ClientCreateLock(testLock);
	if(testLockNum == -1) {
		printf("Create Lock (Normative) failed!\n\n");
	}
	else {
		printf("Create Lock (Normative) succeeded!\n\n");
	}

	// Send the acquire lock message
	printf("Sending acquire lock message (Normative)\n");
	success = ClientAcquireLock(testLock);
	if(success == 0) {
		printf("Acquire Lock (Normative) failed!\n\n");
	}
	else if(success == 1) {
		printf("Acquire Lock (Normative) succeeded!\n\n");
	}

	// Send the release lock message
	printf("Sending release lock message (Normative)\n");
	ClientReleaseLock(testLock);
	if(success == 0) {
		printf("Release Lock (Normative) failed!\n\n");
	}
	else if(success == 1) {
		printf("Release Lock (Normative) succeeded!\n\n");
	}

	printf("Sending delete lock message (Normative)\n");
	ClientDeleteLock(testLock);
	if(success == 0) {
		printf("Delete Lock (Normative) failed!\n\n");
	}
	else if(success == 1) {
		printf("Delete Lock (Normative) succeeded!\n\n");
	}

	// Releasing the deleted lock (should announce deletion)
	printf("Sending release lock message (Normative) (should announce deletion in DEBUG mode n in other window)\n");
	ClientReleaseLock(testLock);
	if(success == 0) {
		printf("Release Lock (Normative) failed!\n\n");
	}
	else if(success == 1) {
		printf("Release Lock (Normative) succeeded!\n\n");
	}

	// NOW FOR SOME NON-NORMATIVES AWWWWWWWWWWWWW YYEEEAAAAAAAHHHHHHHH
	char* testLock1 = "testLck1";
	char* testLock2 = "testLck2";
	
	// Send the create lock messages for lock 1
	printf("Sending create lock messages. Creating the same lock twice\n");
	testLockNum = ClientCreateLock(testLock1);
	if(testLockNum == -1) {
		printf("Create first Lock failed!\n\n");
	}
	else {
		printf("Create first Lock succeeded!\n\n");
	}
	// Send the create lock message for lock 2
	int newTestLockNum = ClientCreateLock(testLock1);
	if(newTestLockNum == -1) {
		printf("Create second Lock failed!\n\n");
	}
	else {
		printf("Create second Lock succeeded!\n\n");
	}

	if(newTestLockNum == testLockNum) {
		printf("Creating two locks succeeded! (TEST SUCCEEDED, returned same value as original lock)\n");
	}
	else {
		printf("Creating two locks failed! (TEST FAILED, returned value different from original lock)\n");
	}

	printf("Done making same lock twice\n\n");


	// Send the create lock message for lock 2
	printf("Sending new create lock message\n");
	testLockNum = ClientCreateLock(testLock2);
	if(testLockNum == -1) {
		printf("Create Lock failed!\n\n");
	}
	else {
		printf("Create Lock succeeded!\n\n");
	}


	printf("Sending release lock message (This should fail, lock has not been acquired)\n");
	success = ClientReleaseLock(testLock2);
	if(success == 0) {
		printf("Release Lock failed! (TEST SUCCEEDED)\n\n");

		// Send the acquire lock message,checking if it still works after a failed release
		printf("Sending acquire lock message (to see if it still works after a failed release)\n");
		success = ClientAcquireLock(testLock2);
		if(success == 0) {
			printf("Acquire Lock failed!\n\n");
		}
		else if(success == 1) {
			printf("Acquire Lock succeeded!\n\n");
		}
		else {
			printf("Message was unable to send\n\n");
		}
	}
	else if(success == 1) {
		printf("Release Lock succeeded! (TEST FAILED)\n\n");
	}
	else {
		printf("Message was unable to send\n\n");
	}
	

	//Send the delete lock message on lock that doesn't exist
	printf("Sending delete lock message (This should fail, lock has not been created)\n");
	success = ClientDeleteLock("DnTeXiSt");
	if(success == -404) {
		printf("Delete Lock failed! (TEST SUCCEEDED)\n\n");
	}
	else if(success == 1) {
		printf("Delete Lock succeeded! (TEST FAILED)\n\n");
	}
	else {
		printf("Message was unable to send\n\n");
	}


	return;
}

void ServerTest_NoDelete(int farAddr) {
	PacketHeader outPktHdr, inPktHdr;
	MailHeader outMailHdr, inMailHdr;
	char *data = "Hello there!";
	char *ack = "Got it!";
	char buffer[MaxMailSize];
	int success;

	// construct packet, mail header for original message
	// To: destination machine, mailbox 0
	// From: our machine, reply to: mailbox 1
	outPktHdr.to = farAddr;		
	//outMailHdr.to = 0;
	outMailHdr.from = myMachID;
	outMailHdr.length = strlen(data) + 1;
	
	int testLockNum;

	char* testLock = "testLock";
	
	// Send the create lock message
	printf("Sending create lock message (Normative)\n");
	testLockNum = ClientCreateLock(testLock);
	if(testLockNum == -1) {
		printf("Create Lock (Normative) failed!\n\n");
	}
	else {
		printf("Create Lock (Normative) succeeded!\n\n");
	}

	// Send the acquire lock message
	printf("Sending acquire lock message (Normative)\n");
	success = ClientAcquireLock(testLock);
	if(success == 0) {
		printf("Acquire Lock (Normative) failed!\n\n");
	}
	else if(success == 1) {
		printf("Acquire Lock (Normative) succeeded!\n\n");
	}

	int testCVNum;
	char* testCV = "testCV";
	
	// Send the create CV message
	printf("Sending create CV message (Normative)\n");
	testCVNum = ClientCreateCV(testCV);
	if(testCVNum == -1) {
		printf("Create CV (Normative) failed!\n\n");
	}
	else {
		printf("Create CV (Normative) succeeded!\n\n");
	}

	printf("COMMENCE WAITING\n");
	ClientWait(testLock, testCV);
	printf("You should not reach this point unless you have signaled\n");

	return;

	// Send the release lock message
	printf("Sending release lock message (Normative)\n");
	ClientReleaseLock(testLock);
	if(success == 0) {
		printf("Release Lock (Normative) failed!\n\n");
	}
	else if(success == 1) {
		printf("Release Lock (Normative) succeeded!\n\n");
	}

	/*printf("Sending delete lock message (Normative)\n");
	ClientDeleteLock(testLock);
	if(success == 0) {
		printf("Delete Lock (Normative) failed!\n\n");
	}
	else if(success == 1) {
		printf("Delete Lock (Normative) succeeded!\n\n");
	}*/

	// Releasing the deleted lock (should announce deletion)
	printf("Sending release lock message (Normative) (should announce deletion in DEBUG mode n in other window)\n");
	ClientReleaseLock(testLock);
	if(success == 0) {
		printf("Release Lock (Normative) failed!\n\n");
	}
	else if(success == 1) {
		printf("Release Lock (Normative) succeeded!\n\n");
	}

	// NOW FOR SOME NON-NORMATIVES AWWWWWWWWWWWWW YYEEEAAAAAAAHHHHHHHH
	char* testLock1 = "testLck1";
	char* testLock2 = "testLck2";
	
	// Send the create lock messages for lock 1
	printf("Sending create lock messages. Creating the same lock twice\n");
	testLockNum = ClientCreateLock(testLock1);
	if(testLockNum == -1) {
		printf("Create first Lock failed!\n\n");
	}
	else {
		printf("Create first Lock succeeded!\n\n");
	}
	// Send the create lock message for lock 2
	int newTestLockNum = ClientCreateLock(testLock1);
	if(newTestLockNum == -1) {
		printf("Create second Lock failed!\n\n");
	}
	else {
		printf("Create second Lock succeeded!\n\n");
	}

	if(newTestLockNum == testLockNum) {
		printf("Creating two locks succeeded! (TEST SUCCEEDED, returned same value as original lock)\n");
	}
	else {
		printf("Creating two locks failed! (TEST FAILED, returned value different from original lock)\n");
	}

	printf("Done making same lock twice\n\n");


	// Send the create lock message for lock 2
	printf("Sending new create lock message\n");
	testLockNum = ClientCreateLock(testLock2);
	if(testLockNum == -1) {
		printf("Create Lock failed!\n\n");
	}
	else {
		printf("Create Lock succeeded!\n\n");
	}


	printf("Sending release lock message (This should fail, lock has not been acquired)\n");
	success = ClientReleaseLock(testLock2);
	if(success == 0) {
		printf("Release Lock failed! (TEST SUCCEEDED)\n\n");

		// Send the acquire lock message,checking if it still works after a failed release
		printf("Sending acquire lock message (to see if it still works after a failed release)\n");
		success = ClientAcquireLock(testLock2);
		if(success == 0) {
			printf("Acquire Lock failed!\n\n");
		}
		else if(success == 1) {
			printf("Acquire Lock succeeded!\n\n");
		}
		else {
			printf("Message was unable to send\n\n");
		}
	}
	else if(success == 1) {
		printf("Release Lock succeeded! (TEST FAILED)\n\n");
	}
	else {
		printf("Message was unable to send\n\n");
	}
	

	//Send the delete lock message on lock that doesn't exist
	/*printf("Sending delete lock message (This should fail, lock has not been created)\n");
	success = ClientDeleteLock("DnTeXiSt");
	if(success == 0) {
		printf("Delete Lock failed! (TEST SUCCEEDED)\n\n");
	}
	else if(success == 1) {
		printf("Delete Lock succeeded! (TEST FAILED)\n\n");
	}
	else {
		printf("Message was unable to send\n\n");
	}*/


	return;
}

void CVTestSuite(int farAddr) {
	PacketHeader outPktHdr, inPktHdr;
	MailHeader outMailHdr, inMailHdr;
	char *data = "Hello there!";
	char *ack = "Got it!";
	char buffer[MaxMailSize];
	int success;
	
	int testCVNum;
	char* testCV = "testCV";
	
	// Send the create CV message
	printf("Sending create CV message (Normative)\n");
	testCVNum = ClientCreateCV(testCV);
	if(testCVNum == -1) {
		printf("Create CV (Normative) failed!\n\n");
	}
	else {
		printf("Create CV (Normative) succeeded!\n\n");
	}
	
	int testLockNum;
	char* testLock = "testLock";
	
	// Send the create lock message
	printf("Sending create lock message (Normative)\n");
	testLockNum = ClientCreateLock(testLock);
	if(testLockNum == -1) {
		printf("Create Lock (Normative) failed!\n\n");
	}
	else {
		printf("Create Lock (Normative) succeeded!\n\n");
	}

	printf("COMMENCING WAIT\n");
	ClientWait(testLock, testCV);
	printf("THIS SHOULD NOT BE REACHED UNLESS YOU SIGNALED\n");
}

void CVTestSuite2(int farAddr) {
	PacketHeader outPktHdr, inPktHdr;
	MailHeader outMailHdr, inMailHdr;

	// construct packet, mail header for original message
	// To: destination machine, mailbox 0
	// From: our machine, reply to: mailbox 1
	
	int testCVNum;
	char* testCV = "testCV";
	
	// Send the create CV message
	printf("Sending create CV message (Normative)\n");
	testCVNum = ClientCreateCV(testCV);
	if(testCVNum == -1) {
		printf("Create CV (Normative) failed!\n\n");
	}
	else {
		printf("Create CV (Normative) succeeded!\n\n");
	}

	int testLockNum;
	char* testLock = "testLock";
	
	// Send the create lock message
	printf("Sending create lock message (Normative)\n");
	testLockNum = ClientCreateLock(testLock);
	if(testLockNum == -1) {
		printf("Create Lock (Normative) failed!\n\n");
	}
	else {
		printf("Create Lock (Normative) succeeded!\n\n");
	}

	// Send the signal CV message
	printf("Sending signal CV message (Normative)\n");
	testCVNum = ClientSignal(testLock, testCV);
	if(testCVNum == -1) {
		printf("Signal CV (Normative) failed!\n\n");
	}
	else {
		printf("Signal CV (Normative) succeeded!\n\n");
	}
}

void CreateCVTest(int farAddr) {
  PacketHeader outPktHdr, inPktHdr;
  MailHeader outMailHdr, inMailHdr;
  char *data;
  char *ack;
  char buffer[MaxMailSize];

  // construct packet, mail header for original message
  // To: destination machine, mailbox 0
  // From: our machine, reply to: mailbox 1
  
  outPktHdr.to = farAddr;		
  outMailHdr.to = 0;
  outMailHdr.from = myMachID;
  outMailHdr.length = strlen(data) + 1;

  // Send the first message
  printf("Sending create lock message\n");
  char *testLockName = "testLock";
  int testLockNum = ClientCreateLock(testLockName);
  printf("Sending acquire lock message\n");
  int isLockAcquired = ClientAcquireLock(testLockName);

  if (isLockAcquired > 0) {
    // Lock is acquired. Proceed.

    // Create the CV.
    char *testCVName = "testCV";
    int createCVSuccess = ClientCreateCV(testCVName);

    if (createCVSuccess == 1) { // SUCCESS
      printf("A CV was created with name %s\n", testCVName); // EXPECTED OUTCOME
    }
    if (createCVSuccess == 0) { // ALREADY EXISTS
      printf("A CV already exists with name %s\n", testCVName);
    }
    if (createCVSuccess == -1) { // NOT CREATED
      printf("A CV was not created.\n");
    }
  }
  else {
    // Lock was not acquired.
	  printf("Lock was not acquired. Test failed.\n");
  }
}

void WaitCVTest(int farAddr) {
  PacketHeader outPktHdr, inPktHdr;
  MailHeader outMailHdr, inMailHdr;
  char *data;
  char *ack;
  char buffer[MaxMailSize];

  // construct packet, mail header for original message
  // To: destination machine, mailbox 0
  // From: our machine, reply to: mailbox 1
  
  outPktHdr.to = farAddr;		
  outMailHdr.to = 0;
  outMailHdr.from = myMachID;
  outMailHdr.length = strlen(data) + 1;

  // Send the first message
  printf("Sending create lock message\n");
  char *testLockName = "testLock";
  int testLockNum = ClientCreateLock(testLockName);
  printf("Sending acquire lock message\n");
  int isLockAcquired = ClientAcquireLock(testLockName);

  if (isLockAcquired > 0) {
    // Create the CV.
    char *testCVName = "testCV";
    int createCVSuccess = ClientCreateCV(testCVName);

    if (createCVSuccess == 1 || createCVSuccess == 0) { // SUCCESS
      printf("A CV was created with name %s\n", testCVName); // EXPECTED OUTCOME
      int cwTest = ClientWait(testLockName, testCVName);

      // Should not be seen until a third instance of nachos (second client)
      // Calls Signal, in order to wake client up
      if (cwTest == 1) { // WOKEN UP VIA SIGNAL OR BROADCAST
	printf("I'm awake!\n");
      }
      else { // FAILURE
	printf("I did not wait.\n");
      }
    }
    if (createCVSuccess == -1) { // NOT CREATED
      printf("A CV was not created.\n");
    }
  }
  else {
    // Lock not acquired
  }
}

void SignalCVTest(int farAddr) {
  PacketHeader outPktHdr, inPktHdr;
  MailHeader outMailHdr, inMailHdr;
  char *data;
  char *ack;
  char buffer[MaxMailSize];

  // construct packet, mail header for original message
  // To: destination machine, mailbox 0
  // From: our machine, reply to: mailbox 1
  
  outPktHdr.to = farAddr;		
  outMailHdr.to = 0;
  outMailHdr.from = myMachID;
  outMailHdr.length = strlen(data) + 1;

  // Send the first message
  printf("Sending create lock message\n");
  char *testLockName = "testLock";
  int testLockNum = ClientCreateLock(testLockName);
  printf("Sending acquire lock message\n");
  int isLockAcquired = ClientAcquireLock(testLockName);

  if (isLockAcquired > 0) {
    // Create the CV.
    char *testCVName = "testCV";
    int createCVSuccess = ClientCreateCV(testCVName);

    if (createCVSuccess == 1 || createCVSuccess == 0) { // SUCCESS
      printf("Beginning Signal test.");
      int cvSignalResults = ClientSignal(testLockName, testCVName);

      // -1 means no server, 0 means failed validation or noone woke up, 1 means someone woke up
      if (cvSignalResults == -1) {
	printf("No server found.");
      }
      if (cvSignalResults == 0) { // EXPECTED RESULT
 	printf("Bad validation or no client to wake up.");
      }
      if (cvSignalResults == 1) {
	printf("I woke someone up!");
      }
    }
    if (createCVSuccess == -1) { // NOT CREATED
      printf("A CV was not created.");
    }
  }
}

void BroadcastCVTest(int farAddr) {
  PacketHeader outPktHdr, inPktHdr;
  MailHeader outMailHdr, inMailHdr;
  char *data;
  char *ack;
  char buffer[MaxMailSize];

  // construct packet, mail header for original message
  // To: destination machine, mailbox 0
  // From: our machine, reply to: mailbox 1
  
  outPktHdr.to = farAddr;		
  outMailHdr.to = 0;
  outMailHdr.from = myMachID;
  outMailHdr.length = strlen(data) + 1;

  // Send the first message
  printf("Sending create lock message\n");
  char *testLockName = "testLock";
  int testLockNum = ClientCreateLock(testLockName);
  printf("Sending acquire lock message\n");
  int isLockAcquired = ClientAcquireLock(testLockName);

  if (isLockAcquired > 0) {
    // Create the CV.
    char *testCVName = "testCV";
    int createCVSuccess = ClientCreateCV(testCVName);

    if (createCVSuccess == 1 || createCVSuccess == 0) { // SUCCESS
      printf("Beginning Broadcast test.");
      int cvBroadcastResults = ClientBroadcast(testLockName, testCVName);

      // -1 means no server, 0 means failed validation or noone woke up, 1 means someone woke up
      if (cvBroadcastResults == -1) {
	printf("No server found.");
      }
      if (cvBroadcastResults == 0) { // EXPECTED RESULT
	printf("Bad validation or no client to wake up.");
      }
      if (cvBroadcastResults == 1) {
	printf("I woke someone up!");
      }
    }
    if (createCVSuccess == -1) { // NOT CREATED
      printf("A CV was not created.");
    }
  }
}

void CVDeleteTest(int farAddr) {
  PacketHeader outPktHdr, inPktHdr;
  MailHeader outMailHdr, inMailHdr;
  char *data;
  char *ack;
  char buffer[MaxMailSize];

  // construct packet, mail header for original message
  // To: destination machine, mailbox 0
  // From: our machine, reply to: mailbox 1
  
  outPktHdr.to = farAddr;		
  outMailHdr.to = 0;
  outMailHdr.from = myMachID;
  outMailHdr.length = strlen(data) + 1;

  // Send the first message
  printf("Sending create lock message\n");
  char *testLockName = "testLock";
  int testLockNum = ClientCreateLock(testLockName);
  printf("Sending acquire lock message\n");
  int isLockAcquired = ClientAcquireLock(testLockName);

  if (isLockAcquired > 0) {
    // Create the CV.
    char *testCVName = "testCV";
    int createCVSuccess = ClientCreateCV(testCVName);

    if (createCVSuccess == 1 || createCVSuccess == 0) { // SUCCESS
      printf("Beginning CV Delete test.");
      int cvDeleteResults = ClientBroadcast(testLockName, testCVName);

      // -1 means no server, 0 means failed validation or noone woke up, 1 means someone woke up
      if (cvDeleteResults == -1) {
	printf("No server found.");
      }
      if (cvDeleteResults == 0) { // EXPECTED RESULT
	printf("Bad validation.");
      }
      if (cvDeleteResults == 1) {
	printf("CV Deleted");
      }
    }
    if (createCVSuccess == -1) { // NOT CREATED
      printf("A CV was not created.");
    }
  }
}

void MVTest(int farAddr) {
  PacketHeader outPktHdr, inPktHdr;
  MailHeader outMailHdr, inMailHdr;
  char *data;
  char *ack;
  char buffer[MaxMailSize];

  // construct packet, mail header for original message
  // To: destination machine, mailbox 0
  // From: our machine, reply to: mailbox 1
  
  outPktHdr.to = farAddr;		
  outMailHdr.to = 0;
  outMailHdr.from = myMachID;
  outMailHdr.length = strlen(data) + 1;

  // Send the first message
  printf("Creating new Monitor.");
  char *testMVName = "testMV";
  int arraySize = 10;

  // -1 is no server, 0 is fail, 1 success
  int createMVSuccess = ClientCreateMV(testMVName, arraySize);	//ERROR HERE

  if (createMVSuccess == 1) { // SUCCESS
    printf("MV Create successful");

    int setMVTest = ClientMVSet(testMVName, 0, 5);

    if (setMVTest == 1) { // SUCCESS
      // Tests if the set worked
      int setValue = ClientMVGet(testMVName, 0);

      printf("MV Value at index 0 is %i\n", setValue);

      // Now to delete.
      int deleteTest = ClientMVDelete(testMVName);
      if (deleteTest == 1) { // SUCCESS 
	printf("MV Delete Test successful");
      }
    }
  }
}
